package Zoo.handler;


import Zoo.entity.ZoomenEntity;
import Zoo.impl.LeaderService1Impl;
import Zoo.service.LeaderService1;
import Zoo.view.leaderview.DeleteZoomenView;
import Zoo.view.leaderview.LeaderView1;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 园长删除动物饲养员界面处理类
 */
public class DeleteZoomenViewHandler implements ActionListener {
    private DeleteZoomenView deleteZoomenView;
    private LeaderView1 leaderView1;


    public DeleteZoomenViewHandler(DeleteZoomenView deleteZoomenView, LeaderView1 leaderView1) {
        this.deleteZoomenView = deleteZoomenView;
        this.leaderView1 = leaderView1;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JButton jButton = (JButton) e.getSource();
        String text = jButton.getText();
        if ("删除".equals(text)) {
            LeaderService1 leaderService1 = new LeaderService1Impl();
            ZoomenEntity zoomenEntity = deleteZoomenView.buildDeletedZoomenEntity();
            boolean deleteResult = leaderService1.delete(zoomenEntity);
            if (deleteResult) {
                //重新加载表格查到最新数据
                leaderView1.reloadTable();
                deleteZoomenView.dispose();
            } else {
                JOptionPane.showMessageDialog(deleteZoomenView, "修改失败");

            }

        }
    }

}
